﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeBackup.Code
{
    public class JsonData
    {
        private static string DatabaseFile =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Database.txt") ;
        public static List<Database> Databases()
        {

            if (!File.Exists(DatabaseFile)) return new List<Database>();

            string json=File.ReadAllText(DatabaseFile);

            List<Database> databases=JsonConvert.DeserializeObject<List<Database>>(json);

            return databases;
        }


        public static void  SaveDatabases(List<Database> database)
        {
            string json= JsonConvert.SerializeObject(database);
             File.WriteAllText(DatabaseFile, json);

        }
    }
}
